package google.sites.view;

import com.google.gdata.data.sites.WebPageEntry;
import dev.tools.view.panels.HtmlPanel;
import google.sites.model.Model;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import javax.swing.*;
import java.awt.*;

/**
 * Created with IntelliJ IDEA.
 * User: Nuno
 * Date: 04-10-2013
 * Time: 21:26
 */
public class WebPageView extends JTabbedPane {
    public WebPageView(WebPageEntry entry) {
        setTabPlacement(JTabbedPane.BOTTOM);
        String source = Model.INSTANCE.getContentBlob(entry);

        HtmlPanel htmlPanel = new HtmlPanel(source);
        add("preview", htmlPanel);

        JPanel panel = new JPanel(new BorderLayout());
        panel.add(new JLabel(entry.getTitle().getPlainText()), BorderLayout.NORTH);
        panel.add(new JTextArea(source));
        JScrollPane scrollPane = new JScrollPane(panel);
        add("source", scrollPane);

        Document document = Jsoup.parse(source);
        Document.OutputSettings outputSettings = document.outputSettings();
        outputSettings.prettyPrint(true);
        document.outputSettings(outputSettings);
        add("pretty", new TextArea(document.outerHtml()));
    }
}
